package 随机码;

import java.io.IOException;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Properties;

/**
 * @author chenhailong
 * @ClassName: Random
 * @Description: TODO
 * @date 2021/4/21 10:27
 * @Version 1.0
 */
public class RandomDemo {

    public static void main(String[] args) throws ParseException, IOException {
//        System.out.println("123456789".substring(0));
        int random = (int) (Math.random() * 100000);
        java.util.Random random2 = new java.util.Random();
        int random1 = random2.nextInt(100);
        System.out.println(" random:" + random);

        System.out.println("随机验证码：" + verifyCode());
        System.out.println(" random2:" + random2);
        System.out.println(" random1:" +random1);

    }


    public static String verifyCode() {
        java.util.Random random = new java.util.Random();
        String str = "";
        for (int i = 0; i < 8; i++){
            int key = random.nextInt(3);
            switch (key){
                case 0:
                    int code1 = random.nextInt(10);
                    str += code1;
                    break;
                case 1:
                    char code2 = (char)(random.nextInt(26)+65);
                    str += code2;
                    break;
                case 2:
                    char code3 = (char)(random.nextInt(26)+97);
                    str += code3;
                    break;
            }
        }
        return str;
    }

}
